var a = getApp();

Page({
    data: {
        pageType: null,
        titleName: "",
        searchValue: "",
        goodsList: [],
        page: 1,
        isLoadMore: !0,
        total_page: 0
    },
    onLoad: function(a) {
        if (a.t) {
            this.setData({
                pageType: a.t
            });
            var t = 2 == a.t ? "代理套餐" : "进货";
            wx.setNavigationBarTitle({
                title: t
            });
        }
        this.getGood();
    },
    onSearchChange: function(a) {
        this.setData({
            searchValue: a.detail
        });
    },
    getGood: function() {
        var t = this, e = null;
        2 == this.data.pageType ? (e = a.getNetAddresss("plugin.new-retail.frontend.index.AgentPackage"), 
        e += "&goods_name=".concat(this.data.searchValue || "")) : (e = a.getNetAddresss("plugin.new-retail.frontend.index.purchaseIndependently"), 
        e += "&search[goods_name]=".concat(this.data.searchValue || "")), a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                1 == e.result ? t.setData({
                    goodsList: e.data.data,
                    isLoadMore: !0,
                    total_page: e.data.last_page
                }) : (wx.navigateBack({
                    delta: 1
                }), wx.showToast({
                    title: e.msg,
                    duration: 2e3,
                    icon: "none"
                }));
            },
            fail: function(a) {
                wx.hideLoading(), console.log(a.msg);
            }
        });
    },
    _getMoreData: function() {
        var t = this;
        if (this.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.data.page += 1;
            var e = null;
            2 == this.data.pageType ? (e = a.getNetAddresss("plugin.new-retail.frontend.index.AgentPackage"), 
            e += "&goods_name=".concat(this.data.searchValue || "")) : (e = a.getNetAddresss("plugin.new-retail.frontend.index.purchaseIndependently"), 
            e += "&search[goods_name]=".concat(this.data.searchValue || "")), e += "&page=".concat(this.data.page), 
            a._postNetWork({
                url: e,
                success: function(a) {
                    var e = a.data;
                    if (t.data.isLoadMore = !0, 1 === e.result) {
                        var o = e.data.data, n = t.data.goodsList.concat(o);
                        t.setData({
                            goodsList: n
                        });
                    } else t.data.page = t.data.page - 1, t.data.isLoadMore = !1;
                }
            });
        }
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this._getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {}
});